package com.azzcs.consumer.config;

import org.apache.dubbo.rpc.*;

/**
 * @Author: wzg
 * @Date: 2021/2/6 上午10:39
 */
public class TPMonitorFilter implements Filter {

    private TPMonitorDataCenter dataCenter;

    public TPMonitorFilter() {
        dataCenter = TPMonitorDataCenter.getInstance();
    }

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String methodName = invocation.getMethodName();
        long startTime = System.currentTimeMillis();
        Result result = invoker.invoke(invocation);
        long executeTime = System.currentTimeMillis() - startTime;
        dataCenter.add(methodName,startTime,executeTime);
        return result;
    }
}
